#include <stdio.h>
#include "../src/common/YXJSON.h"
#include "../src/common/YXMySQL.h"
#include "../src/common/YXResult.h"

int main() {
    char *server   = "120.24.99.196";   // MySQL服务器地址
    int   port     = 3306;              // MySQL服务器端口
    char *user     = "root";            // MySQL用户名
    char *password = "wisdom123456789"; // MySQL密码
    char *database = "mt";              // 数据库名

    // 创建数据源
    DataSource *dataSource = createDataSource(server, port, user, password, database);
    // 获取连接
    Connection *conn = getConnection(dataSource);
    // 执行查询
    MYSQLResult *result = exceuteQuery(conn, "SELECT * FROM user");
    // 打印查询结果
    if (result->type == MYSQL_RESULT_ERROR) {
        printf("Error: %s\n", yxMYSQLResultGetErrMsg(result));
    } else {
        yxArray *array = yxMYSQLResultGetArrayValue(result);
        printf("%s\n", cJSON_Print(YXResultUtils.success("成功", array)));
    }
    // 归还连接
    returnConnection(dataSource, conn);
    // 获取连接
    conn = getConnection(dataSource);
    // 执行查询
    result = exceuteQuery(conn, "SELECT * FROM user");
    // 打印查询结果
    if (result->type == MYSQL_RESULT_ERROR) {
        printf("Error: %s\n", yxMYSQLResultGetErrMsg(result));
    } else {
        yxArray *array = yxMYSQLResultGetArrayValue(result);
        printf("%s\n", cJSON_PrintUnformatted(YXResultUtils.success("成功", array)));
    }
    // 归还连接
    returnConnection(dataSource, conn);


    return 0;
}
